package com.dst.smart.handler.disposer;

import org.json.JSONArray;
import org.json.JSONException;
import android.content.Context;
import android.util.Log;
import com.dst.smart.handler.entity.SemanticResult;
import com.dst.smart.handler.entity.ServiceType;
/**
 *	翻译
 * 切换成英文模式
 	打开翻译
 	把麻婆豆腐翻译成英文
 *
 * author <a href="http://www.xfyun.cn">讯飞开放平台</a>
 * date 2016年9月5日 下午4:58:10
 *
 */
public class TranslationDisposer extends Disposer {

	private  final String KEY_TRANSLATED = "translated";
	
	public TranslationDisposer(Context context) {
		super(context);
	}

	@Override
	public void disposeResult(SemanticResult semanticResult) {
		
		try {
			Log.e("text","Trancelation"+semanticResult.getAnswerText());
			JSONArray result = semanticResult.getResult();
			if(result == null || result.length() == 0) return;
			String translated = result.getJSONObject(0).getString(KEY_TRANSLATED);
			//getPlayController().justTTS("", translated);
			getPlayController().playURLList(semanticResult.getUUID(),null);
			getPlayController().playText(semanticResult.getUUID(), translated , true, 0, "", null);
			//sendAiuiData("翻译","translation",result.toString());
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	@Override
	public boolean canHandle(ServiceType type) {
		return (type.equals(ServiceType.TRANSLATION));
	}

}
